package com.ewhale.feitengguest.presenter.user.message;

import com.ewhale.feitengguest.api.ApiHelper;
import com.ewhale.feitengguest.dto.MessageDetailDto;
import com.ewhale.feitengguest.dto.MessageDto;
import com.ewhale.feitengguest.view.user.message.NewsBulletinView;
import com.simga.library.base.IPresenter;
import com.simga.library.http.APIException;

import java.util.List;

public class NewsBulletinPresenter extends IPresenter {

    public void loadMessageList(int pageNum) {
        request(1, ApiHelper.MESSAGE_API.getMessageList( 10,pageNum), pageNum);
    }

    public void loadMessageDetail(long messageId) {
        request(2, ApiHelper.MESSAGE_API.getMessageDetail(messageId), null);
    }

    @Override
    public <T> void onNext(int postCode, T result, Object data) {
        super.onNext(postCode, result, data);
        switch (postCode) {
            case 1:
                ((NewsBulletinView) mView).showMessageList((List<MessageDto>) result, (int) data);
                break;
            case 2:
                ((NewsBulletinView) mView).showMessageDetail((MessageDetailDto)result);
                break;
        }
    }

    @Override
    public void otherException(int postCode, Object data, APIException e) {
        super.otherException(postCode, data, e);
        mView.showErrorMessage(postCode, e.getCode(), e.getDisplayMessage());
    }
}
